<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>文件查重</title>
	<link rel="stylesheet" href="css/style.css">
	<link rel="stylesheet" href="css/tree.css">
	<script src="cs/jquery.min.js"></script>
	<script src="cs/tree.js"></script>
	<style>
		.file-box {
			position: relative;
			overflow: hidden;
		}

		.file-box #myTFCfile {
			position: absolute;
			width: 100%;
			height: 100%;
			left: 0;
			top: 0;
			opacity: 0;
			cursor: pointer;
		}

		.tfc-nodata {
			text-align: center;
			padding: 150px 0;
		}

		.tfc-nodata img {
			display: inline-block;
			text-align: center;
		}

		.publicBtn {
			display: inline-block;
			padding: 6px 30px;
			background: #c2040e;
			color: #fff;
			border-radius: 4px;
		}
		/*查看*/
		.alert_btn{
			display: none;
		}
		.alert_content{
			height: auto;
		}
		.alert{
			width: 40%;
			margin-left: 30%;
		}
		#jstree .jstree-icon{
			background-image: url(img/nes.png);
		}
		.jstree-default .jstree-themeicon{
			background-position: -165px -4px;
		}
		#jstree{
			padding-top: 20px;
			padding-left: 10px;
		}
		.mask{
			background: rgba(0,0,0,.5);
			width: 100%;
			height: 100%;
			z-index: 99;
			position: absolute;
			top: 0;
			left: 0;
			display: none;

		}

		.boxs{
			background: #fff;
			width: 100%;
			padding-bottom: 20px;
		}
		.nthead{
			background: #e6e6e6;
			color: #333;
			margin-bottom: 0px;

			border-radius: 5px 5px 0 0;
			font-size: 16px;
			line-height: 40px;
			height: 40px;
			padding-left: 20px;
			position: relative;
		}
		.closes{
			line-height: 40px;
			width: 40px;
			display: block;
			text-align: center;
			cursor: pointer;

		}
		.closes img{
			display: inline-block;
		}
		.looking{
			cursor: pointer;
			color: #c2040e;
		}
		.prompt{
			line-height: 40px;
			margin-left: 15px;
		}
	</style>
</head>

<body class="inner_body">
<!-- 添加弹出层 -->
<div class="biu biu1">

	<div class="biu-bg"></div>
	<div class="biu-box">
		<div class="biu-title">
			提示！
			<div class="biu-close" onclick="$(this).parents('.biu').hide()"></div>
		</div>
		<div class="biu-main">

		</div>
		<div class="biu-footer">
		</div>
	</div>
</div>
<div class="crumbs">
	<div class="index-img"></div>
	<a onclick="window.parent.location.reload();" href="javascript:void(0)" class="sy">首页</a><label>&gt;</label><a href="javascript:void(0)"
																												   class="mbx">文件查重</a>
</div>
</div>
<div class="content_box">
	<div class="title_nav clearfix">
		<div class="title_box_select fl active" id="table_one">文件查重</div>
	</div>
	<div class="panel">

		<div class="mainContent">
			<div class="funBox">


				<form class="bs-example bs-example-form from1" role="form" id="searchCriteria">
					<div class="publicBtn fl file-box" style="margin-right:20px;" >上传
						<input type="file" id="myTFCfile" onchange="uploadTFCFile()" />
					</div>
					<span class="prompt"></span>
					<div class="fl inputRight"><label for="departNames">重复率大于:&ensp;</label>
						<select id="selectTFCClass" class="form-control">
							<option value="1" classid='""'>请选择</option>
							<option value="0.9">90%</option>
							<option value="0.8">80%</option>
							<option value="0.7">70%</option>
							<option value="0.6">60%</option>
							<option value="0.5">50%</option>
							<option value="0.4">40%</option>
							<option value="0.3">30%</option>
							<option value="0.2">20%</option>
							<option value="0.1">10%</option>
						</select>
					</div>
					<div style="margin:2px 0 0 20px;" class="fl publicBtn searchBtn" onclick="searchTFC()">查询</div>
				</form>
				<div class="clear"></div>
			</div>
			<div class="clear"></div>
<!--			<div class="prompt">-->
				<!--提示-->
<!--				<div style="margin-top:20px; font-weight: bold; font-size: 18px; color: #717171;" class="">提示 :&ensp;</div>-->
<!--				<div style="font-size:16px; color:#717171;">-->
<!--					请上传zip或者rar文件，当前只对doc和docx类型的文件进行重复率对比。-->
<!--				</div>-->
<!--			</div>-->

			<div class="clear"></div>
			<table id="tfcTable" class="table-style box_1">
				<thead>
				<tr>
					<th class="col-lg-2">序号</th>
					<th class="col-lg-5">文件名</th>
					<th class="col-lg-11">对比文件</th>
					<th class="col-lg-4">相似度</th>
				</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div class="tfc-nodata">
				<img src="img/wjcc.jpg" />
			</div>

			<div class="page">

				<div class="tcdPageCode"></div>

			</div>
			<div class="clear"></div>

			<div class="mask">
				<div class="alert" style="top: 0">
					<p class="nthead">文件查看<span class="fr closes">×</span></p>
					<div class="alert_box boxs">
						<div id="jstree"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
	var jsonArray = [];
	$(function () {

	});
	$('.closes').click(function () {
		$('.mask').css('display','none')
	})
	$('.file-box').click(function () {
		//jsonArray = []

	})
	//上传文件
	function uploadTFCFile() {
		console.log(123);
		var crowd_file = $('#myTFCfile')[0].files[0];
		var formData = new FormData();
		formData.append("file", $('#myTFCfile')[0].files[0]);

		formData.append("userId", parent.result.stuorteaId);
		$.ajax({
			url: '/SchoolMS2.0/doc-check/upload',
			dataType: 'json',
			type: 'POST',
			async: false,
			data: formData,
			processData: false, // 使数据不做处理
			contentType: false, // 不要设置Content-Type请求头
			success: function (data) {
				if (data.code == 200) {
					$('.biu1 .biu-main').html('文件上传成功！');
					$('.biu1').show();
					jsonArray = []
					evalData();
					$('.prompt').html('<span class="looking">查看</span>')
				}

			},
			error: function (response) {
				console.log(response);
			}
		});
	}
	// 处理data树
	function evalData(){
		// var data = '[{"label":"一级1","children":[{"label":"二级1-1","children":[{"label":"三级1-1-1"}]}]},{"label":"一级2","children":[{"label":"二级2-1","children":[{"label":"三级2-1-1"},{"label":"三级2-1-2"}]},{"label":"二级2-2","children":[{"label":"三级2-2-1"},{"label":"三级2-2-2"}]}]}]';
		//var data =[{value: null, label: "000001-实验报告 (2).zip", children:[{"label":"三级1-1-1"}]}]
		// processJson(data,"#");


		$.ajax({
			url: '/SchoolMS2.0/doc-check/view?userId='+parent.result.stuorteaId,
			type: 'GET',
			async: true,
			success: function(data) {
				ss = data.data
				processJson(data.data,"#");
			},
			error: function(data) {
				var json = JSON.stringify({
					"pageName": "error"
				});
				window.location.href = "skipPage?jsonStr=" + json;

			}
		});
	}
	// 解析层级数
	function processJson(data,pid){

		var datas = eval(data);
		if(datas){
			for(var i = 0 ; i < datas.length ; i++){
				var obj = {};
				var da = datas[i];
				obj.parent = pid;
				var id = guid();
				obj.id = id;
				obj.text = da.label;
				if(da.children != '' && da.children != null && da.children.length > 0){
					processJson(da.children,id);
				}
				jsonArray.push(obj);
			}
		}

	}
	//查看
	$('body').on('click','.looking',function(){

		$('#jstree').data('jstree', false).empty();
		console.log(jsonArray,77)
		$("#jstree").jstree({
			"core": {
				'data': jsonArray
			}
		});
		// 展开节点
		$("#jstree").on("loaded.jstree", function (event, data) {
			// 展开所有节点
			$('#jstree').jstree('open_all');
		});

		// 所有节点都加载完后
		$("#jstree").on("ready.jstree", function (event, data) {
			//alert('all ok');
			$('#jstree').jstree('open_all');
		});

		// 获得点击节点的id
		$('#jstree').on("changed.jstree", function (e, data) {
			console.log('node.id is:' + data.node.id);
			console.log('node.text is:'+data.node.text);
		});
		$('.mask').css('display','block')

	})

	//用于生成uuid
	function S4() {
		return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
	}
	function guid() {
		return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
	}

	//查询重复率
	function searchTFC() {
		console.log($('#myTFCfile')[0].files[0]);
		let tfcVal = $("#selectTFCClass").val();
		if ($('#myTFCfile')[0].files[0] == undefined) {
			$('.biu1 .biu-main').html('请上传文件！');
			$('.biu1').show();
			return;
		} else if (tfcVal == 1) {
			$('.biu1 .biu-main').html('请选择重复率！');
			$('.biu1').show();
			return;
		}
		$.ajax({
			url: '/SchoolMS2.0/doc-check?userId=' + parent.result.stuorteaId + '&similarity=' + tfcVal,
			type: 'get',
			success: function (data) {
				console.log(data);
				if (data.code == 200) {
					data = data.data;

					$('.biu1 .biu-main').html('查询成功！');
					$('.biu1').show();
					setTFCList(data);
				}

			},
			error: function (response) {
				console.log(response);
			}
		});
	}
	//查重列表
	function setTFCList(data) {
		$("#tfcTable tbody").empty();
		if (data.length == 0) {
			$(".tfc-nodata").show();
			return;
		}
		$(".tfc-nodata").hide();
		$.each(data, function (i, d) {
			let tr = $("<tr></tr>");
			let td1 = $("<td></td>").html(i + 1);
			let td2 = $("<td></td>").html(d.file);
			let td3 = $("<td></td>").html(d.comparedFile);
			let td4 = $("<td></td>").html(d.similarity);
			tr.append(td1, td2, td3, td4);
			$("#tfcTable tbody").append(tr);
		});
	}
</script>
</body>


</html>